/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.webevo.gui.forms;

import javax.swing.JPanel;
import org.webevo.gui.controllers.ControllerUI_Sampler;
import org.webevo.gui.controllers.ControllerUI_ThresholdCalculator;
import org.webevo.gui.controllers.ControllerUI_WordsMapper;
import org.webevo.gui.panels.mapper.PanelCalculateThreshold;
import org.webevo.gui.panels.mapper.PanelMapWordsTable;
import org.webevo.gui.panels.sampler.PanelSampler;

/**
 *
 * @author Djordje
 */
public class MainForm extends javax.swing.JFrame {

    /**
     * Creates new form MainForm
     */
    public MainForm() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlMain = new javax.swing.JPanel();
        jMenuBar2 = new javax.swing.JMenuBar();
        jMenu3 = new javax.swing.JMenu();
        jMenu4 = new javax.swing.JMenu();
        miMapWords = new javax.swing.JMenuItem();
        miViewWords = new javax.swing.JMenuItem();
        miMeasureThreshold = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        miSampleDataset = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        pnlMain.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        getContentPane().add(pnlMain, java.awt.BorderLayout.CENTER);

        jMenu3.setText("File");
        jMenuBar2.add(jMenu3);

        jMenu4.setText("Mapper");

        miMapWords.setText("Map words");
        miMapWords.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miMapWordsActionPerformed(evt);
            }
        });
        jMenu4.add(miMapWords);

        miViewWords.setText(" View words");
        jMenu4.add(miViewWords);

        miMeasureThreshold.setText(" Measure Threshold");
        miMeasureThreshold.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miMeasureThresholdActionPerformed(evt);
            }
        });
        jMenu4.add(miMeasureThreshold);

        jMenuBar2.add(jMenu4);

        jMenu1.setText("Sample");

        miSampleDataset.setText(" Sample dataset");
        miSampleDataset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miSampleDatasetActionPerformed(evt);
            }
        });
        jMenu1.add(miSampleDataset);

        jMenuBar2.add(jMenu1);

        setJMenuBar(jMenuBar2);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void miMapWordsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miMapWordsActionPerformed
        ControllerUI_WordsMapper mc = new ControllerUI_WordsMapper();
        PanelMapWordsTable mapWords = new PanelMapWordsTable();
        mc.setViewWOrdsTable(mapWords);
        mapWords.setCoordinator(mc);
//        ControllerUI_Main.getInstance().setActivePanel(activePanel);
        setActivePanel(mapWords);
    }//GEN-LAST:event_miMapWordsActionPerformed

    private void miMeasureThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miMeasureThresholdActionPerformed
        ControllerUI_ThresholdCalculator tc = new ControllerUI_ThresholdCalculator();
        PanelCalculateThreshold calculateThreshold = new PanelCalculateThreshold();
        tc.setPanelCalculateThreshold(calculateThreshold);
        calculateThreshold.setController(tc);

        setActivePanel(calculateThreshold);
    }//GEN-LAST:event_miMeasureThresholdActionPerformed

    private void miSampleDatasetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSampleDatasetActionPerformed
        PanelSampler panelSampler = new PanelSampler();
        ControllerUI_Sampler controllerSampler = new ControllerUI_Sampler();
        controllerSampler.setPanelSampler(panelSampler);
        panelSampler.setController(controllerSampler);

        setActivePanel(panelSampler);
    }//GEN-LAST:event_miSampleDatasetActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainForm().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JMenuItem miMapWords;
    private javax.swing.JMenuItem miMeasureThreshold;
    private javax.swing.JMenuItem miSampleDataset;
    private javax.swing.JMenuItem miViewWords;
    private javax.swing.JPanel pnlMain;
    // End of variables declaration//GEN-END:variables
    private JPanel activePanel;

    public void setActivePanel(JPanel newPanel) {
        if (activePanel != null) {
            this.remove(activePanel);
        }

        activePanel = newPanel;
        getContentPane().add(activePanel, java.awt.BorderLayout.SOUTH);
        activePanel.setVisible(true);
        validate();
        repaint();
        pack();
        System.out.println("Done");
    }
}
